package com.example.leetdemo.finash;

import java.util.Comparator;
import java.util.PriorityQueue;

public class Solution1508 {

    public int rangeSum(int[] nums, int n, int left, int right) {
        PriorityQueue<Integer> queue = new PriorityQueue<>(Comparator.comparingInt(o -> o));
        for (int i = 0; i < nums.length; i++) {
            int num = 0;
            for (int j = i; j < nums.length; j++) {
                num += nums[j];
                queue.add(num);
            }
        }
        for (int i = 1; i < left; i++) {
            queue.poll();
        }
        int result = 0, MAXVALUE = 1000000007;
        for (int i = 0; i <= right - left; i++) {
            result += queue.poll();
            result = result % MAXVALUE;
        }
        while (queue.size() > 0) {
            System.err.println(queue.poll());
        }
        return result;
    }


    public static void main(String[] args) {
        Solution1508 solution1508 = new Solution1508();
        System.err.println(solution1508.rangeSum(new int[] {1,2,3,4}, 4, 1, 5));
    }
}
